/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2024-03-18 10:58:44
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-05-17 16:42:23
 * @FilePath: /yt-devops/lib/components/yt_bottom_picker.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/resources/resources.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';

ytBottomPicker(
  BuildContext context, {
  double minHeight = 452,
  required void Function() mainButtonOnTap,
  required void Function(void Function(void Function()) setState) resetTap,
  required Widget Function(BuildContext) builder,
  void Function()? onClose,
}) {
  showModalBottomSheet(
    context: context,
    isScrollControlled: true,
    backgroundColor: Colors.white,
    // useSafeArea: true,
    shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
            topLeft: Radius.circular(10.w), topRight: Radius.circular(10.w))),
    constraints: BoxConstraints(minHeight: minHeight.h, maxHeight: 654.h),
    builder: (context) {
      return StatefulBuilder(
        builder: (context, setState) {
          return Stack(children: [
            Container(
              padding: EdgeInsets.fromLTRB(20.w, 20.h, 20.w, 116.h),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  /// 表头筛选及关闭
                  Container(
                    margin: EdgeInsets.only(bottom: 20.h),
                    child: InkWell(
                      onTap: () {
                        Get.back();
                        onClose?.call();
                      },
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: <Widget>[
                          Text(
                            ResKey.filter.tr,
                            style: TextStyles.f18.boldStyle,
                          ),
                          const Icon(
                            Icons.close,
                            color: Colour.hintTextColor,
                          )
                        ],
                      ),
                    ),
                  ),

                  /// 筛选项目
                  Flexible(
                    child: ListView(
                      shrinkWrap: true,
                      children: <Widget>[
                        builder(context),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Positioned(
              bottom: 34,
              left: 20.w,
              right: 20.w,
              child: Container(
                padding: const EdgeInsets.only(top: 16),
                decoration: const BoxDecoration(
                    color: Colors.white,
                    boxShadow: [BoxShadow(color: Colour.shadowColor)]),
                child:

                    /// 执行按钮
                    Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Gaps.line,
                    SizedBox(
                      child: GestureDetector(
                        onTap: () => resetTap(setState),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Image.asset(
                              ImageAssets.iconRenew,
                              width: 20.w,
                              height: 20.h,
                            ),
                            Text(
                              ResKey.reset.tr,
                              style: TextStyle(
                                color: Colour.mainTextColor,
                                fontSize: 14.sp,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.only(left: 18.w),
                        child: BrnBigMainButton(
                          title: ResKey.confirm.tr,
                          themeData: BrnButtonConfig(),
                          onTap: mainButtonOnTap,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            )
          ]);
        },
      );
    },
  );
}
